package com.asj.house.service.impl;

import com.asj.house.entity.HouseRoom;
import com.asj.house.entity.HouseRoomMap;
import com.asj.house.mapper.HouseRoomMapMapper;
import com.asj.house.returns.RespCode;
import com.asj.house.returns.RespEntity;
import com.asj.house.service.HouseRoomMapService;
import com.asj.house.service.HouseRoomService;
import com.asj.house.utils.ConverterUtil;
import com.asj.house.vo.result.RoomMapResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 房屋地图信息表 服务实现类
 * </p>
 *
 * @author asj
 * @since 2021-03-04
 */
@Service
public class HouseRoomMapServiceImpl extends ServiceImpl<HouseRoomMapMapper, HouseRoomMap> implements HouseRoomMapService {

    @Autowired
    private HouseRoomService houseRoomService;

    @Override
    public RespEntity<List<HouseRoomMap>> listHouseRoomMap() {
        QueryWrapper<HouseRoomMap> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(HouseRoomMap::getDeleted, 0);
        List<HouseRoomMap> houseRoomMapList = baseMapper.selectList(queryWrapper);
        return new RespEntity<>(RespCode.SUCCESS, houseRoomMapList);
    }

    @Override
    public RespEntity<RoomMapResult> getRoomMap(Integer roomId) {
        QueryWrapper<HouseRoomMap> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(HouseRoomMap::getRoomId, roomId)
                .eq(HouseRoomMap::getDeleted, 0);
        HouseRoomMap houseRoomMap = baseMapper.selectOne(queryWrapper);

        HouseRoom houseRoom = houseRoomService.getById(roomId);

        RoomMapResult roomMapResult = ConverterUtil.copyProperties(houseRoomMap, RoomMapResult.class);
        roomMapResult.setUrl(houseRoom.getUrl());

        return new RespEntity<>(RespCode.SUCCESS, roomMapResult);
    }
}
